package ModelLayer;
import java.util.ArrayList;

/**
 * The DVD class is a DVD.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVD
{
    private int id;
    private String title;
    private String artist;
    private String releaseDate;
    private ArrayList<Copy> copies;

    /**
     * Constructor for objects of class DVD
     * 
     * @param id - the id of the DVD
     * @param title - the title of the DVD
     * @param artist - the artist of the DVD
     * @param pubDate - the publishing date of the DVD
     */
    public DVD(int id, String title, String artist, String releaseDate)
    {
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.releaseDate = releaseDate;
        copies = new ArrayList<Copy>();
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public int getId()
    {
        return id;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public String getArtist()
    {
        return artist;
    }
    
    public String getReleaseDate()
    {
        return releaseDate;
    }
    
    public void setTitle(String newTitle)
    {
        title = newTitle;
    }
    
    public void setArtist(String newArtist)
    {
        artist = newArtist;
    }
    
    public void setReleaseDate(String newReleaseDate)
    {
        releaseDate = newReleaseDate;
    }
    
    public void addCopy(Copy newCopy)
    {
        copies.add(newCopy);
    }

    public Copy searchCopy(String searchSerialNumber)
    {
        boolean found = false;
        int index = 0;
        while(index < copies.size() && !found)
        {
            if(copies.get(index).getSerialNumber().equals(searchSerialNumber))
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        if(found == true)
        {
            return copies.get(index);
        }
        else
        {
            return null;
        }
    }

    /**
     * Update a DVD
     * 
     * @param id - get the DVD by the serialNumber
     * @param title - update the purchaseDate
     * @param artist - update the purchasePrice
     */
    public void updateCopy(String serialNumber, String purchaseDate, double purchasePrice)
    {
        Copy copy = searchCopy(serialNumber);
        if(copy != null)
        {
            copy.setSerialNumber(serialNumber);
            copy.setPurchaseDate(purchaseDate);
            copy.setPurchasePrice(purchasePrice);
        }
    }
    
    public void deleteCopy(String serialNumber)
    {
        Copy copy = searchCopy(serialNumber);
        if(copy != null)
        {
            copies.remove(copy);
        }
    }

    
    

    
    public void printInfo()
    {
        System.out.println("Id: " + getId());
        System.out.println("Title: " + getTitle());
        System.out.println("Artist: " + getArtist());
        System.out.println("Release Date: " + getReleaseDate());
    }
    
    
 public void listAllCopies()
    {
        for(Copy copy : copies)
        {
            copy.printInfo();
        }
    }

}
